package yunwo.cn.yzstation.model;

import android.util.Log;
import android.widget.Toast;

import com.google.gson.Gson;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;
import yunwo.cn.yzstation.api.HttpManager;
import yunwo.cn.yzstation.api.okapi.GLCallBack;
import yunwo.cn.yzstation.bean.CinfoBean;
import yunwo.cn.yzstation.config.MyConstants;
import yunwo.cn.yzstation.presenter.TrainnumberPersenter;
import yunwo.cn.yzstation.utils.StringUtil;
import yunwo.cn.yzstation.view.activity.TrainnumberActivity;

/**
 * Created by lao on 2017/10/16.
 */
public class TrainnumberM {
    TrainnumberActivity trainnumberActivity;
    TrainnumberModel trainnumberModel;

    public TrainnumberM(TrainnumberActivity trainnumberActivity, TrainnumberModel trainnumberModel) {
        this.trainnumberActivity = trainnumberActivity;
        this.trainnumberModel = trainnumberModel;

    }

    public void getCarData(final String type, int page) {
        Map<String, Object> map = new HashMap<>();
        map.put("isShort", "1");
        map.put("status", "2,3,4,5");
        map.put("isStowage", "2");
        HttpManager.hpptPostPageStringmer(MyConstants.carlist,page,10,map).execute(new GLCallBack() {

            private CinfoBean.DataBean mDataBean;

            @Override
            public void onResponseT(String result, int code, String msg, int id) {
                if (code == 200) {
                    if (!StringUtil.isEmpty(result)) {
                        mDataBean = new Gson().fromJson(result, CinfoBean.DataBean.class);
                        trainnumberModel.getDataSueecss(type,mDataBean);
                    }
                }else {
                    trainnumberModel.getDataFailure();
                    Toast.makeText(trainnumberActivity, msg, Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onError(Call call, Exception e, int id) {
                Toast.makeText(trainnumberActivity, "出错了", Toast.LENGTH_SHORT).show();
                trainnumberModel.getDataFailure();
            }
        });
    }
}
